package edu.hcmus.sow.domain;

import java.io.Serializable;
import java.util.Calendar;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllTaskWorkLogs", query = "select myTaskWorkLog from TaskWorkLog myTaskWorkLog"),
		@NamedQuery(name = "findTaskWorkLogById", query = "select myTaskWorkLog from TaskWorkLog myTaskWorkLog where myTaskWorkLog.id = ?1"),
		@NamedQuery(name = "findTaskWorkLogByLoggedDate", query = "select myTaskWorkLog from TaskWorkLog myTaskWorkLog where myTaskWorkLog.loggedDate = ?1"),
		@NamedQuery(name = "findTaskWorkLogByNote", query = "select myTaskWorkLog from TaskWorkLog myTaskWorkLog where myTaskWorkLog.note = ?1"),
		@NamedQuery(name = "findTaskWorkLogByPrimaryKey", query = "select myTaskWorkLog from TaskWorkLog myTaskWorkLog where myTaskWorkLog.id = ?1"),
		@NamedQuery(name = "findTaskWorkLogByTimeSpent", query = "select myTaskWorkLog from TaskWorkLog myTaskWorkLog where myTaskWorkLog.timeSpent = ?1") })
@Table(catalog = "sow", name = "task_work_log")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain", name = "TaskWorkLog")
public class TaskWorkLog implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "ID", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@XmlElement
	Integer id;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "LOGGED_DATE")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar loggedDate;
	/**
	 */

	@Column(name = "TIME_SPENT")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer timeSpent;
	/**
	 */

	@Column(name = "NOTE", columnDefinition = "TEXT")
	@Basic(fetch = FetchType.EAGER)
	@Lob
	@XmlElement
	String note;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "LOGGED_BY", referencedColumnName = "ID") })
	@XmlTransient
	User user;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "TASK_ID", referencedColumnName = "ID", nullable = false) })
	@XmlTransient
	Task task;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setLoggedDate(Calendar loggedDate) {
		this.loggedDate = loggedDate;
	}

	/**
	 */
	public Calendar getLoggedDate() {
		return this.loggedDate;
	}

	/**
	 */
	public void setTimeSpent(Integer timeSpent) {
		this.timeSpent = timeSpent;
	}

	/**
	 */
	public Integer getTimeSpent() {
		return this.timeSpent;
	}

	/**
	 */
	public void setNote(String note) {
		this.note = note;
	}

	/**
	 */
	public String getNote() {
		return this.note;
	}

	/**
	 */
	public void setUser(User user) {
		this.user = user;
	}

	/**
	 */
	@JsonIgnore
	public User getUser() {
		return user;
	}

	/**
	 */
	public void setTask(Task task) {
		this.task = task;
	}

	/**
	 */
	@JsonIgnore
	public Task getTask() {
		return task;
	}

	/**
	 */
	public TaskWorkLog() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(TaskWorkLog that) {
		setId(that.getId());
		setLoggedDate(that.getLoggedDate());
		setTimeSpent(that.getTimeSpent());
		setNote(that.getNote());
		setUser(that.getUser());
		setTask(that.getTask());
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("loggedDate=[").append(loggedDate).append("] ");
		buffer.append("timeSpent=[").append(timeSpent).append("] ");
		buffer.append("note=[").append(note).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof TaskWorkLog))
			return false;
		TaskWorkLog equalCheck = (TaskWorkLog) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
